package com.hdaccp.foodsales.dao;

import com.hdaccp.foodsales.entity.Gonghuo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GonghuoDao {

    /**
     * 分页查询所以user
     * @param spage
     * @param epage
     * @return
     */
    @Select("select g.*,d.dept_name from gonghuo g LEFT JOIN tb_dept d ON d.dept_id=g.dept_id ORDER BY ghid desc limit #{spage},#{epage}")
    public List<Gonghuo> getUserList(@Param("spage") int spage, @Param("epage") int epage);

    /**
     * 统计user表总数量
     * @return
     */
    @Select("select count(*) from gonghuo g  ")
    public int getUserCount();


    /**
     * 添加用户操作表
     * @param uid
     * @param type
     * @param name
     * @return
     */
    @Insert("insert into tb_user_opt(u_id,uopt_name,uopt_type,uopt_time) values(#{uid},#{name},#{type},sysdate())")
    public int insertUserOpt(@Param("uid") int uid, @Param("type") String type, @Param("name") String name);

    /**
     * 根据用户登录账号查询
     * @param account
     * @return
     */
    @Select("select * from gonghuo where ghuo = #{ghuo}")
    public List<Gonghuo> getUserByAccount(String account);


    /**
     * 添加用户信息
     * @param user
     * @return
     */
    @Insert("insert into gonghuo(dept_id,ghuo,ghxm,ghdizhi,ghphone,ghbeizhu)"
            + " values(#{dept_id},#{ghuo},#{ghxm},#{ghdizhi},#{ghphone},#{ghbeizhu})")
    public int saveUser(Gonghuo user);


    /**
     * 删除用户操作表
     * @param uid
     * @return
     */
    @Delete("delete from tb_user_opt where u_id=#{uid}")
    public int delUserOpt(int uid);

    /**
     * 删除用户表
     * @param id
     * @return
     */
    @Delete("delete from gonghuo where ghid=#{uid}")
    public int delUser(int id);

    /**
     * 根据用户id查询用户信息
     * @param id
     * @return
     */
    @Select("select * from gonghuo where ghid=#{id}")
    public Gonghuo queryUserById(int id);



    /**
     * 查询所有用户信息以及其对应的部门
     * @return
     */
    @Select("select g.*,d.dept_name from gonghuo g,tb_dept d where d.dept_id =g.dept_id")
    public List<Gonghuo> queryUserList();
    /**
     * 条件查询用户
     * @param ghid
     * @param ghxm
     * @param deptId
     * @return
     */
    public List<Gonghuo> getUserListByCon(@Param("spage") int spage, @Param("epage") int epage, @Param("ghid") Integer ghid, @Param("ghxm") String ghxm, @Param("deptId") Integer deptId);

    /**
     * 根据条件统计数量
     * @param ghid
     * @param ghxm
     * @param deptId
     * @return
     */
    public int getContByCon(@Param("ghid") Integer ghid, @Param("ghxm") String ghxm, @Param("deptId") Integer deptId);



}
